package com.ea.eadp.nexus.test.pageDefinition;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;

/**
 * Created by ChuanYe on 9/8/2014.
 */
public class EmailVerifyContinuePage extends BasePage{
    private static String ERROR_MESSAGE_EMAIL_NOT_VERIFIED = "This email has not been verified";
    private static String INFO_MESSAGE_RESEND_EMAIL = "Another verification email has been sent to your email:";
    private static String ERROR_MESSAGE_RESEND_EMAIL_RECENTLY = "An email has already been sent. Please try to resend again after 1 min.";
    private static String identifierId="btnNext";
    public EmailVerifyContinuePage(WebDriver driver) {
        super(driver, EmailVerifyContinuePage.class);
    }
    public void waitPageLoadCompleted() {
        WebDriverWait wait = new WebDriverWait(driver, 30, 1000);
        wait.until(ExpectedConditions.elementToBeClickable(By.id(identifierId)));
    }
    public void navigate(String uri) {
        driver.navigate().to(uri);
    }

    public void continueLogin() {
        //driver.findElement(By.cssSelector("span > span")).click();
        driver.findElement(By.id("btnNext")).click();
    }

    public void resendmail() {
        driver.findElement(By.id("btnResend")).click();
    }

    public void cancel() {
        driver.findElement(By.id("btnCancel")).click();
    }

    public void verifyNotVerifiedErrorMessgeExist() {
        WebElement element = driver.findElement(By.id("email-verification-error"));
        Assert.assertNotNull(element, "not able to locate the email not verified error message");
        Assert.assertTrue(element.getText().contains(ERROR_MESSAGE_EMAIL_NOT_VERIFIED));
    }

    public void verifyResendEmailInfoMessgeExist() {
        WebElement element = driver.findElement(By.className("email-verification-banner-padding"));
        Assert.assertNotNull(element, "not able to locate the resend email info message");
        Assert.assertTrue(element.getText().contains(INFO_MESSAGE_RESEND_EMAIL));
    }

    public void verifyResendEmailErrorMessgeExist() {
        WebElement element = driver.findElement(By.className("email-verification-banner-padding"));
        Assert.assertNotNull(element, "not able to locate the resend email info message");
        Assert.assertTrue(element.getText().contains(ERROR_MESSAGE_RESEND_EMAIL_RECENTLY));
    }
}
